package com.future.mapper;

import com.future.entity.Person;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

/**
 * <P>
 *
 * </p>
 *
 * @author yinhao
 * @version 1.0
 * @since 2024/9/11 14:18
 */
public interface PersonMapperAnnotation {

    @Select("select * from t_person p,t_idencard iden where p.id=#{id} and p.card_id=iden.id")

    // 注解方式,多表联查
    @Results({
            @Result(property = "id", column = "id",id = true),
            @Result(property = "name", column = "name"),
            // @Result(property = "idenCard", javaType = IdenCard.class),
            @Result(property = "idenCard.id", column = "card_id"),
            @Result(property = "idenCard.card_sn", column = "card_sn")
    })
    Person findPersonById(Integer id);

    // 注解方式,子查询
    @Select("select * from t_person where id = #{id}")
    @Result(property = "id", column = "id")
    @Result(property = "name", column = "name")
    @Result(property = "idenCard", column = "card_id", one = @One(select = "com.future.mapper.IdenCardMapperAnnotation.findIdenCardById"))
    Person findPersonById2(Integer id);


}
